package com.ddwl.user.controller;


import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.user.JoinerApproveBo;
import com.ddwl.schema.bo.user.JoinerBo;
import com.ddwl.schema.bo.user.QueryJoinerBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.user.JoinerVo;
import com.ddwl.user.service.JoinerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 招商接口
 * @author wenbin
 */
@Api(tags = "招商接口")
@RequestMapping("/join")
@RestController
public class JoinerController extends BaseController {

    @Resource
    private JoinerService joinerService;

    @PostMapping("/createJoiner")
    @ApiOperation("创建或修改加盟商")
    public RestVo<String> createAndUpdate(@Valid @RequestBody JoinerBo bo) {
        bo.setJoinerDk(getDk());
        return RestVo.ok(joinerService.create(bo));
    }

    @PostMapping("/approveJoiner")
    @ApiOperation("审批加盟商")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo approveJoiner(@Valid @RequestBody JoinerApproveBo bo) {
        joinerService.approve(bo);
        return RestVo.ok();
    }


    @PostMapping("/queryJoiner")
    @ApiOperation("查询审批加盟商列表")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<PageVo<JoinerVo>> queryJoinerList(@Valid @RequestBody PageBo<QueryJoinerBo> pageBo) {
        return RestVo.ok(joinerService.list(pageBo));
    }
}
